package kuoge.practice.concurrent.aqs.injvm;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class Latch {
    public static void main(String[] args) {
        int count = 10;
        final List<CompletableFuture<Void>> cfs = new ArrayList<>();
        while (count-- > 0) {
            cfs.add(CompletableFuture.runAsync(() -> {
                try {
                    System.out.println(Thread.currentThread().getName());
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    // ignore
                }
            }));
        }
        CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])).orTimeout(1, TimeUnit.SECONDS).join();
        System.out.println("in main thread xxx: " + Thread.currentThread().getName());
    }
}